package zdm.aop;

import zdm.annotation.aop.ZdmAround;
import zdm.annotation.aop.ZdmAspect;
import zdm.core.aop.ProceedingJoinPoint;

import java.util.Arrays;

@ZdmAspect
public class TimeLoggingAspect {

    @ZdmAround("@zdm.annotation.aop.Loggable")
    public Object logExecutionTime(ProceedingJoinPoint pjp) throws Throwable {
        long startTime = System.currentTimeMillis();
        System.out.println("====== [AOP Around] 方法开始执行 ======");

        // 使用 pjp.getMethod().getName() 来安全地获取方法名
        System.out.println("  -> 目标方法: " + pjp.getTarget().getClass().getInterfaces()[0].getSimpleName() + "." + pjp.getMethod().getName());

        System.out.println("  -> 请求参数: " + Arrays.toString(pjp.getArgs()));

        Object result = pjp.proceed();

        long endTime = System.currentTimeMillis();
        System.out.println("  -> 方法执行结果: " + result);
        System.out.println("====== [AOP Around] 方法执行结束，耗时: " + (endTime - startTime) + " ms ======");

        return result;
    }
}